//
//  TabViewBootcamp.swift
//  FCSwiftUI
//
//  Created by 冯宣超 on 2023/3/2.
//

import SwiftUI

private enum TabType {
    case home, browse, profile
}

struct TabViewBootcamp: View {
    var body: some View {
        SampleViewOne()
        SampleViewTwo()
    }
}

private struct SampleViewOne: View {
    @State var selectedTab: Int = 0
    
    var body: some View {
        TabView(selection: $selectedTab) {
            HomeView(selectedTab: $selectedTab)
                .tabItem {
                    Image(systemName: "house.fill")
                    Text("Home")
                }
                .tag(0)
            
            Text("BROWSE TAB")
                .tabItem {
                    Image(systemName: "globe")
                    Text("Browse")
                }
                .tag(1)
            
            Text("PROFILE TAB")
                .tabItem {
                    Image(systemName: "person.fill")
                    Text("Profile")
                }
                .tag(2)
        }
        .tint(.red)
    }
}

private struct HomeView: View {
    @Binding var selectedTab: Int
    
    var body: some View {
        ZStack {
            Color.red
            VStack {
                Text("HOME TAB")
                    .font(.largeTitle)
                .foregroundColor(.white)
                
                Button {
                    selectedTab = 2
                } label: {
                    Text("Go To Profile")
                        .font(.headline)
                        .padding()
                        .padding(.horizontal)
                        .background(Color.white)
                        .cornerRadius(10)
                }
            }
        }
    }
}

private struct SampleViewTwo: View {
    let images: [String] = [
        "heart.fill", "globe", "house.fill", "person.fill"
    ]
    
    var body: some View {
        TabView {
            ForEach(images, id: \.self) { image in
                RoundedRectangle(cornerRadius: 25.0)
                    .fill(
                        RadialGradient(
                            colors: [.red, .blue],
                            center: .topLeading,
                            startRadius: 5,
                            endRadius: 250
                        )
                    )
                    .padding()
                    .overlay {
                        Image(systemName: image)
                            .resizable()
                            .scaledToFit()
                            .padding(50)
                            .foregroundColor(.green)
                    }
            }
        }
        .frame(height: 300)
        .tabViewStyle(.page)
    }
}

struct TabViewBootcamp_Previews: PreviewProvider {
    static var previews: some View {
        TabViewBootcamp()
    }
}

